package com.fau.cm.entity;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.apache.commons.lang3.time.DateFormatUtils;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.GenericGenerator;
import org.json.simple.JSONAware;
import org.json.simple.JSONObject;

/**
 * @desc 媒体投放信息表
 * @author dangjh
 * @datetime 2014年11月6日,下午8:19:19
 */
@Entity
@Table(name = "medical_media_placement")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class MedicalMediaPlacement implements Serializable, JSONAware {

	private static final long serialVersionUID = -168446559947623684L;

	private String id;
	
	private MedicalMediaInfo media;
	private String publishNumbers;
	private BigDecimal costs;
	private Date placeStartTime;
	private Date placeEndTime;
	private String startTime;
	private String endTime;
	private String playing;
	private String description;
	private Date createTime = new Date();
	private Date updateTime = new Date();
	
	private String mediaId;
	private String play;

	public MedicalMediaPlacement(){
	}
	
	@Id
	@GenericGenerator(name = "generator", strategy = "uuid.hex")
	@GeneratedValue(generator = "generator")
	@Column(name = "ID", length = 32)
	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "media_id")
	public MedicalMediaInfo getMedia() {
		return media;
	}

	public void setMedia(MedicalMediaInfo media) {
		this.media = media;
	}

	@Column(name = "publish_numbers", length = 32)
	public String getPublishNumbers() {
		return publishNumbers;
	}

	public void setPublishNumbers(String publishNumbers) {
		this.publishNumbers = publishNumbers;
	}

	@Column(name = "costs", length = 20)
	public BigDecimal getCosts() {
		return costs;
	}

	public void setCosts(BigDecimal costs) {
		this.costs = costs;
	}

	@Column(name = "place_start_time")
	public Date getPlaceStartTime() {
		return placeStartTime;
	}

	public void setPlaceStartTime(Date placeStartTime) {
		this.placeStartTime = placeStartTime;
	}

	@Column(name = "place_end_time")
	public Date getPlaceEndTime() {
		return placeEndTime;
	}

	public void setPlaceEndTime(Date placeEndTime) {
		this.placeEndTime = placeEndTime;
	}

	@Column(name = "start_time", length = 15)
	public String getStartTime() {
		return startTime;
	}

	public void setStartTime(String startTime) {
		this.startTime = startTime;
	}

	@Column(name = "end_time", length = 15)
	public String getEndTime() {
		return endTime;
	}

	public void setEndTime(String endTime) {
		this.endTime = endTime;
	}

	@Column(name = "playing", length = 20)
	public String getPlaying() {
		return playing;
	}

	public void setPlaying(String playing) {
		this.playing = playing;
	}

	@Column(name = "description", length = 255)
	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	@Column(name = "create_time")
	public Date getCreateTime() {
		return createTime;
	}

	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}

	@Column(name = "update_time")
	public Date getUpdateTime() {
		return updateTime;
	}

	public void setUpdateTime(Date updateTime) {
		this.updateTime = updateTime;
	}

	@Transient
	public String getMediaId() {
		return mediaId;
	}

	public void setMediaId(String mediaId) {
		this.mediaId = mediaId;
	}

	@Transient
	public String getPlay() {
		return play;
	}

	public void setPlay(String play) {
		this.play = play;
	}
	
	@SuppressWarnings("unchecked")
	@Override
	public String toJSONString() {
		JSONObject obj = new JSONObject();
		obj.put("id", id);
		obj.put("mediaName", media.getName());
		obj.put("mediaId", media.getId());
		obj.put("publishNumbers", publishNumbers);
		obj.put("costs", costs);
		obj.put("placeStartTime", DateFormatUtils.format(placeStartTime, "yyyy-MM-dd"));
		obj.put("placeEndTime", DateFormatUtils.format(placeEndTime, "yyyy-MM-dd"));
		obj.put("startTime", startTime);
		obj.put("endTime", endTime);
		obj.put("playing", playing);
		obj.put("play", play);
		obj.put("description", description);
		obj.put("createTime", DateFormatUtils.format(createTime, "yyyy-MM-dd"));
		obj.put("updateTime", DateFormatUtils.format(updateTime, "yyyy-MM-dd"));
		return obj.toJSONString();
	}

}
